#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
    ll l, r;
    cin >> l >> r;
    ll w = r - l;
    while(1) {
        for(ll x = l; x < r - w + 1; x++) {
            ll y = x + w;
            if(gcd(x, y) == 1) {
                cout << w << '\n';
                return 0;
            }
        }
        w--;
    }    
    return 0;
}